package com.yehaikeji.workflow.controller.management;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.util.StringUtil;
import com.yehaikeji.workflow.bean.incident;
import com.yehaikeji.workflow.controller.bean.ResultMessage;
import com.yehaikeji.workflow.service.incidentService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RequestMapping("incidentManager")
@Controller
public class incidentController {

	@Autowired
	private incidentService incidentService;

	//  根据不同的typeid结合当前的status判断所要输入的内容
	// 一体化救助平台 typeid=4:同代办
	// 代发 typeid=3含义     :部门已交件,社区已接件
	//     status=     :     8  ,  9
	// 代收 typeid=2含义     :社区已交件,部门已接件
	// 代办 typeid=1含义     :社区已交件,部门已接件，办结;返件-部门已交件，返件-社区已接件;退件-部门已交件，退件-社区已接件;
	//     status=     :  1      2        3   4             5           6            7    ;
	//status为空则表示未签名
	
	
	@RequestMapping(value = "incidentthing", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "要签字操作接口",notes="点击下一步提交时调用,根据不同的typeid结合当前的status判断所要输入的内容")
	public ResultMessage incidentthing(incident incident) {
		ResultMessage resultMessage = new ResultMessage();
		try {
			if (StringUtil.isEmpty(incident.getThingid())
					|| incident.getStatus() == null || StringUtil.isEmpty(incident.getUserid())
					|| incident.getCreatedate() == null) {
				throw new RuntimeException("参数为空");
			}
			resultMessage.setData(incidentService.insertnextincident(incident));
			resultMessage.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			resultMessage.setMessage(e.getMessage());
			resultMessage.setSuccess(false);
		}
		return resultMessage;
	}
	
	@RequestMapping(value = "incidentthingok", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "直接确定操作接口",notes="点击下一步提交时调用,根据不同的typeid结合当前的status判断所要输入的内容")
	public ResultMessage incidentthinga(incident incident) {
		ResultMessage resultMessage = new ResultMessage();
		try {
			System.out.println(incident);
			if (StringUtil.isEmpty(incident.getThingid())
					|| incident.getStatus() == null || StringUtil.isEmpty(incident.getUserid())
					|| incident.getCreatedate() == null) {
				throw new RuntimeException("参数为空");
			}
			resultMessage.setData(incidentService.insertnextincidenta(incident));
			resultMessage.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			resultMessage.setMessage(e.getMessage());
			resultMessage.setSuccess(false);
		}
		return resultMessage;
	}

	@RequestMapping(value = "incidentthingsignature", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "签名接口",notes="点击签名完成时调用")
	public ResultMessage incidentthingsignature(String incidentid,@ApiParam(value="交件者签名") String signatures,
			@ApiParam(value="接件者签名")String signaturea) {
		ResultMessage resultMessage = new ResultMessage();
		try {
			if (StringUtil.isEmpty(incidentid)){
				throw new RuntimeException("incidentid参数为空");
			}
			if(StringUtil.isEmpty(signaturea)) {
				throw new RuntimeException("signaturea参数为空");
			}
			incidentService.signature(incidentid,signatures, signaturea);
			resultMessage.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			resultMessage.setMessage(e.getMessage());
			resultMessage.setSuccess(false);
		}
		return resultMessage;
	}
	/**
	 * @param thingid
	 * @return
	 */
	@RequestMapping(value = "incidentselectstatus", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value = "可选状态")
	public ResultMessage incidentselectstatus(String thingid) {
		ResultMessage resultMessage = new ResultMessage();
		try {
			if(StringUtil.isEmpty(thingid)) {
				throw new RuntimeException("参数为空");
			}
			resultMessage.setData(incidentService.incidentselectstatus(thingid));
			resultMessage.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			resultMessage.setMessage(e.getMessage());
			resultMessage.setSuccess(false);
		}
		return resultMessage;
	}
}
